Hi,
I'm writing a daemon and now that must be run in a single process (two instance of process should not be executed at the same time). I tried this code, but it didn't work:
Code:
    int lfp=open(LOCK_FILE, O_RDWR|O_CREAT,0640);
    if (lfp<0)
        cout << "Could not open lockfile" << endl;

    if ( lockf(lfp,F_TLOCK,0)<0 )
        exit(0); /* can not lock */
    
    /* first instance continues */

    char str[10];
    sprintf(str,"%d\n",getpid());
    write(lfp,str,strlen(str)); /* record pid to lockfile */
    close(lfp);
What's wrong?!

Thanks